"""
#!!===========================================================
#版权（C）2023, Huawei Technologies Co., HUTAF xDevice
#!!===========================================================
#文 件 名:      SecurityUserIamFingerPrintAuthApi.py
#文件说明:      FingerPrintFace相关公共AW
#作   者:
#生成日期:
#!!===========================================================
"""

# -*- coding: utf-8 -*-
from devicetest.aw.OpenHarmony import CommonOH
from devicetest.core.test_case import keyword
from aw.Useriam.AuthWidget import SecurityUserIamAuthWidgetCommon


@keyword
def setFingerPrint(oh_device):
    """
    #======================================================================
    #   @Method:           setFingerPrint(oh_device)
    #   @Precondition:
    #   @Func:             预置指纹
    #   @Param:
    #   @Example:
    #======================================================================
    """
    SecurityUserIamAuthWidgetCommon.enterhapseeting(oh_device)
    CommonOH.touchByText(oh_device, "预置指纹")


@keyword
def fingerprintAuth(oh_device, finger_type=0):
    """
    #======================================================================
    #   @Method:           fingerprintAuth(oh_device, finger_type)
    #   @Precondition:
    #   @Func:             指纹认证
    #   @Param:            finger_type:指纹认证，0:使用正确指纹认证，1:使用错误指纹认证，2:取消认证
    #   @Example:
    #======================================================================
    """
    if finger_type == 0:
        CommonOH.touchByType(oh_device, type="Image", index=4)
    elif finger_type == 1:
        CommonOH.touchByText(oh_device, "取消")
    elif finger_type == 2:
        CommonOH.touchByText(oh_device, "使用密码")
    else:
        print("您输入的type值错误，请传入正确的type值")
        return False


@keyword
def unclockface(oh_device, pin, pin_type=0):
    """
    #======================================================================
    #   @Method:           unclockface(oh_device, pin,pin_type)
    #   @Precondition:
    #   @Func:             解除指纹锁定
    #   @Param:            pin:设置的pin码
    #   @Param:            pin_type: 0：6位数字密码,1：自定义数字密码,2：混合密码。默认值为0
    #   @Example:
    #======================================================================
    """
    CommonOH.touchByText(oh_device, "使用密码")
    if pin_type == 0:
        CommonOH.touchByText(oh_device, text=pin[0])
        CommonOH.touchByText(oh_device, text=pin[1])
        CommonOH.touchByText(oh_device, text=pin[2])
        CommonOH.touchByText(oh_device, text=pin[3])
        CommonOH.touchByText(oh_device, text=pin[4])
        CommonOH.touchByText(oh_device, text=pin[5])
    elif pin_type == 1:
        CommonOH.inputTextByType(oh_device, "TextInput", pin)
        CommonOH.touchByText(oh_device, "确定")
    elif pin_type == 2:
        CommonOH.inputTextByType(oh_device, "TextInput", pin)
        CommonOH.touchByText(oh_device, "确定")
    else:
        print("您输入的type错误，请输入正确的type值")
        return False


@keyword
def switchpin(oh_device, pin, pin_type=0):
    """
        #======================================================================
        #   @Method:           switchpin(oh_device, pin,pin_type)
        #   @Precondition:
        #   @Func:             切换口令认证
        #   @Param:            pin:设置的pin码
        #   @Param:            pin_type: 0：6位数字密码,1：自定义数字密码,2：混合密码。默认值为0
        #   @Example:
        #======================================================================
        """
    CommonOH.touchByText(oh_device, "使用密码")
    if pin_type == 0:
        CommonOH.touchByText(oh_device, text=pin[0])
        CommonOH.touchByText(oh_device, text=pin[1])
        CommonOH.touchByText(oh_device, text=pin[2])
        CommonOH.touchByText(oh_device, text=pin[3])
        CommonOH.touchByText(oh_device, text=pin[4])
        CommonOH.touchByText(oh_device, text=pin[5])
    elif pin_type == 1:
        CommonOH.inputTextByType(oh_device, "TextInput", pin)
        CommonOH.touchByText(oh_device, "确定")
    elif pin_type == 2:
        CommonOH.inputTextByType(oh_device, "TextInput", pin)
        CommonOH.touchByText(oh_device, "确定")
    else:
        print("您输入的type错误，请输入正确的type值")
        return False
